package com.yima.baseproj.module.app.parent;


import com.yima.baseproj.module.sys.parent.ParentEntity;
import com.yima.baseproj.module.app.parent.model.ParentStuAddModel;
import com.yima.baseproj.module.sys.parent.ParentService;
import com.yima.baseproj.module.sys.parent.student.ParentStudentEntity;
import com.yima.baseproj.module.sys.parent.student.ParentStudentService;
import com.yima.baseproj.module.sys.student.StudentEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import java.util.List;

@Api(tags = "小程序家长")
@RestController
@RequestMapping("/api/app/parent")
public class AppParentController {

    @Autowired
    private ParentService parentService;

    @Autowired
    private AppParentService appParentService;

    @Autowired
    private ParentStudentService parentStudentService;

    /**
     * 存前端小程序传的的家长信息
     * @param parent
     */
    @PostMapping("/add")
    public int save(@RequestBody ParentEntity parent){
        appParentService.save(parent);
        return parent.getId();
    }

    @GetMapping("/findByVxId/{parentVxId}")
    public ParentEntity findByVxId(@PathVariable String parentVxId){
        return appParentService.findByVxId(parentVxId);
    }

    @ApiOperation("查询绑定的学生列表")
    @GetMapping(value = "/findStuAllByParentId/{parentId}")
    public List<StudentEntity> findStuAllByParentId(@PathVariable int parentId) {

        return parentStudentService.getParentStudent(parentId);
    }

    @ApiOperation("新增关联的学生")
    @PostMapping(value = "/parentStuAdd")
    public void parentStuAdd(@Validated @RequestBody  ParentStuAddModel ps){

        parentService.parentStuAdd(ps);
    }


    @ApiOperation("取消关联的学生")
    @PostMapping(value = "/parentStuDel")
    public void parentStuDel(@Validated @RequestBody ParentStudentEntity ps){
        parentService.parentStuDel(ps);
    }


    @ApiOperation("查询是否关联学生")
    @PostMapping(value = "/parentStuFind")
    public int parentStuFind(@Validated @RequestBody ParentStudentEntity ps){
        return parentService.parentStuFind(ps);
    }


}
